$file="test";
#$file = 'out_canonical_strand_negative_10000';
open(BUFF,"$file");
open(WRBUFF,">result_$file");
#$line=<BUFF>;
while($line=<BUFF>)
{
	chomp($line);
	@array = split("\t",$line);
	$start = $array[1]/50;
	$stop = $array[2]/50;
	#print $start."\n";
	if($start =~ m/\./)
	{
		@start = split(/\./,$start);
		$start  = $start[0]*50;
		#print $start."\n";
	}
	else
	{
		$start = ($start-1)*50;
	}	
	if($stop =~ m/\./)
	{
		@stop = split(/\./,$stop);
		$stop = ($stop[0]+1)*50;
	}
	else
	{
		$stop = $stop*50;
	}
	for($i=$start;$i<=$stop-50;$i=$i+50)
	{
		$first = $i+1;
		$second = $i+50;
		print WRBUFF "$array[0]\t$first\t$second\t$array[3]\n";
	}
}
system("sort -k1,1 -k2,2n -k3,3n -k4,4 result_$file > sort_result_$file");
open(BUFF,"sort_result_$file") or die "no sort_result_$file \n";
open(WRBUFF,">result_$file");
$k = "";
while(<BUFF>)
{
	chomp($_);
	@array = split("\t",$_);
	if($k eq "$array[0]_$array[1]_$array[2]")
	{
		print WRBUFF "_$array[3]";
	}
	else
	{
		if($k ne "")
		{
			print WRBUFF "\n";
		}
		print WRBUFF "$array[0]_$array[1]_$array[2]\t$array[3]";
	}
	$k = "$array[0]_$array[1]_$array[2]";
}
print WRBUFF "\n";

